<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <title>教学方案管理</title>
        <include file='Layout:ins_css' />
        <style type="text/css">
            #addBtn {
                float: right;
                margin: -7px -6px 9px;
            }
        </style>
    </head>
    <body>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>教学方案管理</h5>
                            <button class="btn btn-primary" id="addBtn">新增</button>
                        </div>
                        <div class="row s-row">
                            <div class="col-sm-12">
                                <div class="price-div">
                                    <form class="form-horizontal">
                                        <div class="form-group cyf-form-group">
                                            <div class="col-sm-4" style="margin-top: 10px; margin-bottom: 10px">
                                                <label style="float: left;" class="col-sm-4 control-label cvbnm">课程: </label>
                                                <select class="form-control col-sm-" id="course_id" name="course_id" style="min-height: 35px">
                                                    <option value="0">全部</option>
                                                    <volist name="course_info" id="vo">
                                                        <option value="{$vo.cou_id}" class="select">{$vo.name}
                                                        </option>
                                                    </volist>
                                                </select>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <table class="table table-striped table-bordered table-hover dataTables-example">
                                <thead>
                                <tr>
                                    <th width="12.66%">编号</th>
                                    <th width="16.66%">名称</th>
                                    <th width="16.66%">创建人</th>
                                    <th width="16.66%">所属课程</th>
                                    <th width="16.66%">更新时间 </th>
                                    <th width="20.66%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Modal 编辑专业-->
        <div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="ModalLabel"></h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" id="form_add">
                            <div class="hidden" >
                                <label class="col-sm-3 control-label ">方案编号</label>
                                <div class="col-sm-7">
                                    <input type="text" readonly="readonly" id="edit_tme_id" name="edit_tme_id" class="form-control removeData">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">方案名称</label>
                                <div class="col-sm-7">
                                    <input type="text" id="teame_name" name="teame_name" class="form-control removeData">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label cvbnm nationality">所属课程</label>
                                <select class="form-control poiu" id="cou_boss" name="cou_boss" style="width: 300px">
                                    <option value="0">请选择</option>
                                    <volist name="course_info" id="vo">
                                        <option value="{$vo.cou_id}">{$vo.name}</option>
                                    </volist>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label cvbnm nationality">实验语言</label>
                                <select class="form-control poiu" id="lan_boss" name="lan_boss" style="width: 300px">
                                    <option value="0">请选择</option>
                                    <volist name="language_info" id="vo">
                                        <option value="{$vo.language_name}">{$vo.language_name}</option>
                                    </volist>
                                </select>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="add_btn">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <include file='Layout:ins_js' />
        <script type="text/javascript">
            $(document).ready(function () {
                sTable = $(".table").DataTable({
                    "fnServerParams": function (aoData) {
                        aoData.push({
                            'name': 'course_id',
                            'value': $('select#course_id option:selected').val(),
                        });
                    },
                    "bAutoWidth": false,
                    "oLanguage": {
                        "sLengthMenu": "每页 _MENU_ ",
                        "sProcessing": "处理中...",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    },
                    "sAjaxSource": "__URL__/teaching_method_ShowDatatables", //调用php后台接口方法地址
                    "aoColumns": [{
                        'data': 'id'
                    }, {
                        'data': 'me_name'
                    }, {
                        'data': 'tea_name'
                    }, {
                        'data': 'name'
                    },{
                        'data': 'date'
                    },{
                        "data": null,
                        orderable: false,
                        render: function (data, type, row, meta) {
                            return '<a type="button" class="btn btn-success" href="#" onclick=editFromID(this) >编辑</a>|<a type="button" class="btn btn-danger" href="#" onclick=delFromID(this) >删除</a>'
                        }
                    }]
                });
            });
            //table查询
            $('select#course_id').change(function () {
                sTable.ajax.reload();
            });
            <!--------------   新增模态框相关     !----------------->
            //新增模态框弹出
            $('#addBtn').on('click',function () {
               document.getElementById('ModalLabel').innerText = '新增教学方案';
               $('#Modal').modal();
            });
            $("#add_btn").on('click', function() {
                var formData = $('#form_add').serializeArray();
                var model_title = $('#ModalLabel').text();
                var postData = {};
                $(formData).each(function(i) {
                    postData[this.name] = this.value;
                });
                if (model_title.trim() == '新增教学方案'){
                    sil_loading();
                    $.ajax({
                        type: "post",
                        url: "__URL__/add_teachermethod",
                        async: true,
                        data: postData,
                        dataType: 'json',
                        success: function(p) {
                            if(p.state) {
                                toastr.success(p.info);
                                $("#Modal").modal('hide');
                                sTable.ajax.reload();
                            } else {
                                toastr.warning(p.info);
                            }
                            sil_reloading();
                        }
                    });
                }else if (model_title.trim() == '编辑教学方案') {
                    sil_loading();
                    $.ajax({
                        type: "post",
                        url: "__URL__/edit_teachermethod",
                        async: true,
                        data: postData,
                        dataType: 'json',
                        success: function(p) {
                            if(p.state) {
                                toastr.success(p.info);
                                $("#Modal").modal('hide');
                                sTable.ajax.reload();
                            } else {
                                toastr.warning(p.info);
                            }
                            sil_reloading();
                        }
                    });
                }else {

                }
            });
            <!--------------   编辑模态框相关     !----------------->
            //编辑模态框弹出
            function editFromID(obj) {
                $row = $(obj).parent().parent();
                var row = sTable.row($row).data();
                document.getElementById('ModalLabel').innerText = '编辑教学方案';
                $('#edit_tme_id').val(row.id);
                $('#teame_name').val(row.me_name);
                $('#cou_boss').val(row.cou_id);
                $('#lan_boss').val((row.lan_name == null) ? 0 : row.lan_name);
                $('#Modal').modal();
            }
            <!--------------   删除模态框相关     !----------------->
            //删除
            function  delFromID(obj) {
                $row = $(obj).parent().parent();
                sTable.$('tr').addClass('cyf_selected');
                var row = sTable.row($row).data();
                swal({
                    title: '确定要删除吗?',
                    text: '该方案将删除',
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if(isConfirm === true) {
                        sil_loading();
                        $.ajax({
                            type: "post",
                            url: "__URL__/delete_teachermethod",
                            data: {
                                'delete_tme_id': row.id,
                            },
                            dataType: "json",
                            async: true,
                            error: function(request) {
                                toastr.warning("Connection error");
                            },
                            success: function(data) {
                                if(data.state == true) {
                                    toastr.success(data.info);
                                    sTable.ajax.reload();
                                } else {

                                    toastr.warning(data.info);
                                }
                                sil_reloading();
                            }
                        });
                    } else if(isConfirm === false) {

                    } else {

                    }
                });
            }


            // $("#select_course").find("option").each(function (data) {
            //     var $this = $(this);
            //     if($this.text() == row.name) {
            //         $this.attr("selected", true);
            //     }
            // });
            // select2ByText ("select_course", row.name);
            // $("#select_teacher").find("option").each(function (data) {
            //     var $this = $(this);
            //     if($this.text() == row.tea_name) {
            //         $this.attr("selected", true);
            //     }
            // });
            // select2ByText ("select_teacher", row.name);


















        </script>
    </body>
</html>